package com.aj.http.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.aj.databases.entry.FamilySpace;
import com.aj.databases.entry.FamilyZoneInfo;

public class FamilyZoneResponse extends BaseRespond {

	private List<FamilySpace> familySpaceList;

	private List<FamilyZoneInfo> familyZoneInfoList;

	public FamilyZoneResponse(JSONObject json) {
		super(json);
		try {
			if (common != null && common.getResult() != null
					&& common.getResult().has("list")) {
				familySpaceList = new ArrayList<FamilySpace>();
				JSONArray jsonArray = common.getResult().getJSONArray("list");
				familySpaceList = new ArrayList<FamilySpace>();
				for (int i = 0; i < jsonArray.length(); i++) {
					FamilySpace familySpace = new FamilySpace();
					JSONObject jsonObject = jsonArray.getJSONObject(i);
					familySpace.setId(jsonObject.optString("id"));
					familySpace.setAjNo(jsonObject.optString("ajNo"));
					if (jsonObject.isNull("photo")) {
						familySpace.setPhoto(jsonObject.optString("photo"));
					}
					if (jsonObject.isNull("nickName")) {
						familySpace.setNickName("");
					} else {
						familySpace.setNickName(jsonObject
								.optString("nickName"));
					}
					if (jsonObject.isNull("nonage")) {
						familySpace.setNonage("N");
					} else {
						familySpace.setNonage(jsonObject.optString("nonage"));
					}

					familySpaceList.add(familySpace);
				}

			}
			if (common != null && common.getResult() != null
					&& common.getResult().has("AlbumList")) {
				JSONArray tempJsonArray = common.getResult().getJSONArray(
						"AlbumList");
				familyZoneInfoList = new ArrayList<FamilyZoneInfo>();
				for (int j = 0; j < tempJsonArray.length(); j++) {
					JSONObject jsonObjectTemp = tempJsonArray.getJSONObject(j);
					FamilyZoneInfo familyZoneInfo = new FamilyZoneInfo();
					familyZoneInfo
							.setZoneId(jsonObjectTemp.optString("zoneId"));
					familyZoneInfo.setZoneName(jsonObjectTemp
							.optString("zoneName"));
					familyZoneInfo.setZoneUrl(jsonObjectTemp
							.optString("zoneUrl"));
					familyZoneInfo.setPhotoNumber(jsonObjectTemp
							.optInt("photoNumber"));
					familyZoneInfoList.add(familyZoneInfo);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public List<FamilyZoneInfo> getFamilyZoneInfoList() {
		return familyZoneInfoList;
	}

	public void setFamilyZoneInfoList(List<FamilyZoneInfo> familyZoneInfoList) {
		this.familyZoneInfoList = familyZoneInfoList;
	}

	public List<FamilySpace> getFamilySpaceList() {
		return familySpaceList;
	}

	public void setFamilySpaceList(List<FamilySpace> familySpaceList) {
		this.familySpaceList = familySpaceList;
	}

}
